//获取上周起始时间结束时间、下周起始时间结束时间开始时间和本周起始时间结束时间
function getTime(n, iDate) {
		var now = iDate || new Date();
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var day = now.getDay(); //返回星期几的某一天;
        n = day == 0 ? n + 6 : n + (day - 1)
        now.setDate(now.getDate() - n);
        date = now.getDate();
		month = now.getMonth()+1;
		var s = year + "-" + (month < 10 ? ('0' + month) : month) + "-" + (date < 10 ? ('0' + date) : date);
	  return {
		  dateStr: s,
		  year,
		  month: (month < 10 ? ('0' + month) : month),
		  day: (date < 10 ? ('0' + date) : date),
		  newDate: now
	  };
}

function getDayArr7(dayNum){
	let days = []
	let startMonth = "";
	let endMonth = ""
	for (var i = 0; i < 7; i++) {
		days.push(getTime(dayNum-i).day)
	}
	startMonth = getTime(dayNum).month
	endMonth = getTime(dayNum-6).month
	return {
		days,
		startMonth,
		endMonth,
	}
}

module.exports = {
	getTime: getTime,
	getDayArr7: getDayArr7
}